<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属领域" prop="domain">
        <el-input
          v-model="queryParams.domain"
          placeholder="请输入所属领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:submissions:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:submissions:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:submissions:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:submissions:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="submissionsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键ID，自动递增" align="center" prop="id" />-->
      <el-table-column label="中文名称" show-overflow-tooltip     align="center" prop="chineseName" />
      <el-table-column label="英文名称" show-overflow-tooltip     align="center" prop="englishName" />
      <el-table-column label="定义"  show-overflow-tooltip    align="center" prop="definition" />
      <el-table-column label="所属领域"  show-overflow-tooltip    align="center" prop="domain" />
      <el-table-column label="背景"  show-overflow-tooltip    align="center" prop="background" />
      <el-table-column label="发展历程" show-overflow-tooltip     align="center" prop="developmentHistory" />
      <el-table-column label="研究方向"  show-overflow-tooltip    align="center" prop="researchDirections" />
      <el-table-column label="应用场景"  show-overflow-tooltip    align="center" prop="applicationScenarios" />
      <el-table-column label="优势特点"  show-overflow-tooltip    align="center" prop="advantagesFeatures" />
      <el-table-column label="未来趋势"  show-overflow-tooltip    align="center" prop="futureTrends" />
      <el-table-column label="代表人物"  show-overflow-tooltip    align="center" prop="representativePersonsCompanies" />
      <el-table-column label="相关项目" show-overflow-tooltip     align="center" prop="relatedProjects" />
      <el-table-column label="技术难点"  show-overflow-tooltip    align="center" prop="technicalDifficulties" />
      <el-table-column label="顶刊文献" show-overflow-tooltip     align="center" prop="topicalLiterature" />
      <el-table-column label="标准规范"  show-overflow-tooltip    align="center" prop="standardsRegulations" />
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:submissions:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:submissions:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改前沿技术对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="定义" prop="definition">
          <el-input v-model="form.definition" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属领域" prop="domain">
          <el-input v-model="form.domain" placeholder="请输入所属领域" />
        </el-form-item>
        <el-form-item label="背景" prop="background">
          <el-input v-model="form.background" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发展历程" prop="developmentHistory">
          <el-input v-model="form.developmentHistory" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="研究方向" prop="researchDirections">
          <el-input v-model="form.researchDirections" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="应用场景" prop="applicationScenarios">
          <el-input v-model="form.applicationScenarios" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="优势特点" prop="advantagesFeatures">
          <el-input v-model="form.advantagesFeatures" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="未来趋势" prop="futureTrends">
          <el-input v-model="form.futureTrends" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="代表人物" prop="representativePersonsCompanies">
          <el-input v-model="form.representativePersonsCompanies" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="相关项目" prop="relatedProjects">
          <el-input v-model="form.relatedProjects" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="技术难点" prop="technicalDifficulties">
          <el-input v-model="form.technicalDifficulties" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="顶刊文献" prop="topicalLiterature">
          <el-input v-model="form.topicalLiterature" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="标准规范" prop="standardsRegulations">
          <el-input v-model="form.standardsRegulations" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="8"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="8"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="8"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="8"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSubmissions, getSubmissions, delSubmissions, addSubmissions, updateSubmissions } from "@/api/business/submissions";
import { guid } from '@/utils/utils'
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  name: "Submissions",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 前沿技术表格数据
      submissionsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        englishName: null,
        definition: null,
        domain: null,
        background: null,
        developmentHistory: null,
        researchDirections: null,
        applicationScenarios: null,
        advantagesFeatures: null,
        futureTrends: null,
        representativePersonsCompanies: null,
        relatedProjects: null,
        technicalDifficulties: null,
        topicalLiterature: null,
        standardsRegulations: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseName: [
          { required: true, message: "中文名称不能为空", trigger: "blur" }
        ],
        englishName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        definition: [
          { required: true, message: "定义不能为空", trigger: "blur" }
        ],
        domain: [
          { required: true, message: "所属领域不能为空", trigger: "blur" }
        ],
        background: [
          { required: true, message: "背景不能为空", trigger: "blur" }
        ],
        developmentHistory: [
          { required: true, message: "发展历程不能为空", trigger: "blur" }
        ],
        researchDirections: [
          { required: true, message: "研究方向不能为空", trigger: "blur" }
        ],
        applicationScenarios: [
          { required: true, message: "应用场景不能为空", trigger: "blur" }
        ],
        advantagesFeatures: [
          { required: true, message: "优势特点不能为空", trigger: "blur" }
        ],
        futureTrends: [
          { required: true, message: "未来趋势不能为空", trigger: "blur" }
        ],
        representativePersonsCompanies: [
          { required: true, message: "代表人物不能为空", trigger: "blur" }
        ],
        relatedProjects: [
          { required: true, message: "相关项目不能为空", trigger: "blur" }
        ],
        technicalDifficulties: [
          { required: true, message: "技术难点不能为空", trigger: "blur" }
        ],
        topicalLiterature: [
          { required: true, message: "顶刊文献不能为空", trigger: "blur" }
        ],
        standardsRegulations: [
          { required: true, message: "标准规范不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询前沿技术列表 */
    getList() {
      this.loading = true;
      listSubmissions(this.queryParams).then(response => {
        this.submissionsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        englishName: null,
        definition: null,
        domain: null,
        background: null,
        developmentHistory: null,
        researchDirections: null,
        applicationScenarios: null,
        advantagesFeatures: null,
        futureTrends: null,
        representativePersonsCompanies: null,
        relatedProjects: null,
        technicalDifficulties: null,
        topicalLiterature: null,
        standardsRegulations: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加前沿技术";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSubmissions(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改前沿技术";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSubmissions(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSubmissions(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除前沿技术编号为"' + ids + '"的数据项？').then(function() {
        return delSubmissions(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/submissions/export', {
        ...this.queryParams
      }, `submissions_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
